
import axios from "axios";
import { GetToken } from "./auth";

// 旧实例（保持兼容）
const legacyService = axios.create({
    baseURL: process.env.VUE_APP_API_BASE_URL || 'http://localhost:8090',
    timeout: 15000, headers: {
        'Content-Type': 'application/json' // 必须设置
    }
});

// 公共请求拦截器（旧实例和新实例共享）
const injectToken = (config) => {
    const token = GetToken();
    if (token) config.headers.token = token;
    return config;
};

legacyService.interceptors.request.use(injectToken);

// 新实例：上传专用
export const uploadService = axios.create({
    baseURL: process.env.VUE_APP_API_BASE_URL || 'http://localhost:8090',
    timeout: 60000, headers: {
        'Content-Type': 'application/json' // 必须设置
    }
});
uploadService.interceptors.request.use(config => {
    config = injectToken(config);
    config.headers['Content-Type'] = 'multipart/form-data';
    return config;
});

// 重要！保持默认导出旧实例
export default legacyService;